package feeinterface.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.ulwx.tool.DbUtils;

import feeinterface.modeldb.MobileExt;

public class MobileExtDao {
	private static final Logger log = Logger.getLogger(MobileExtDao.class);

	public static MobileExt getByIMSI(String IMSI) throws Exception {
		String sql = "select * from MobileExt where IMSI=?";
		
		Map<Integer, Object> map = new HashMap<Integer, Object>();
		map.put(1, IMSI);
		List<MobileExt> list = DbUtils.doQueryClass(null, MobileExt.class, sql,
				map);
		if (list.size() > 0)
			return list.get(0);
		return null;
	}
	public static void updateGetPhoneCnt(String imsi){
		String sql="update MobileExt set MonthGetPhoneCnt=MonthGetPhoneCnt+1," +
				"DayGetPhoneCnt=DayGetPhoneCnt+1 where IMSI=?";
		try{
			Map<Integer, Object> map = new HashMap<Integer, Object>();
			map.put(1, imsi);
			DbUtils.executeBindUpdate(null, sql, map);
		}catch(Exception e){
			log.error("",e);
		}
	}
	public static void InsertOrUpdate(MobileExt me) {

		try {
			MobileExt meold = MobileExtDao.getByIMSI(me.getIMSI());
			if (meold == null) {// 如果为空则插入

				DbUtils.excuteInsertClass(null, me);

			} else {// 更新
				DbUtils.excuteUpdateClass(null, me, "IMSI"); 
			}
		} catch (Exception e) {
			log.error("", e);
		}

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
